<?php

class Quad_Form_Element_Select extends Quad_Form_Element {
	
	protected $_value;
	protected $_options;
	public $selectedIndex;
	
	public function __construct($label, $value='') {
		$this->setOptions(array());
		parent::__construct('select', $label, $value);
		$this->addClassName('q-form-select');
	}
	
	public function setOptions(array $options) {
		unset($this->_options);
		$this->_options = new Quad_Form_Element_OptionsCollection($this, $options);
		$this->_options->setValue($this->_value);
		return $this;
	}
	
	public function __get($p) {
		if ($p == 'options') {
			return $this->_options;
		}
		return parent::__get($p);
	}
	
	public function __set($p,$v) {
		if ($p == 'options') {
			throw new Quad_Form_Exception('`options` property is read only.');
		}
		parent::__set($p,$v);
	}
	
	public function getOptions() {
		return $this->_options;
	}
	
	public function setValue($v) {
		$this->_value = $v;
		$this->_options->setValue($v);
	}
	
	public function getValue() {
		return $this->_options->getValue();
	}
	
	public function _getInnerHTML() {
		return (string) $this->_options;
	}
	
}

